package com.ruoyi.project.system.banner.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.banner.domain.TBanner;
import com.ruoyi.project.system.banner.service.ITBannerService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * banner配置Controller
 * 
 * @author ruoyi
 * @date 2024-01-24
 */
@Controller
@RequestMapping("/system/banner")
public class TBannerController extends BaseController
{
    private String prefix = "system/banner";

    @Autowired
    private ITBannerService tBannerService;

    @RequiresPermissions("system:banner:view")
    @GetMapping()
    public String banner()
    {
        return prefix + "/banner";
    }

    /**
     * 查询banner配置列表
     */
    @RequiresPermissions("system:banner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TBanner tBanner)
    {
        startPage();
        List<TBanner> list = tBannerService.selectTBannerList(tBanner);
        return getDataTable(list);
    }

    /**
     * 导出banner配置列表
     */
    @RequiresPermissions("system:banner:export")
    @Log(title = "banner配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TBanner tBanner)
    {
        List<TBanner> list = tBannerService.selectTBannerList(tBanner);
        ExcelUtil<TBanner> util = new ExcelUtil<TBanner>(TBanner.class);
        return util.exportExcel(list, "banner配置数据");
    }

    /**
     * 新增banner配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存banner配置
     */
    @RequiresPermissions("system:banner:add")
    @Log(title = "banner配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TBanner tBanner)
    {
        return toAjax(tBannerService.insertTBanner(tBanner));
    }

    /**
     * 修改banner配置
     */
    @RequiresPermissions("system:banner:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TBanner tBanner = tBannerService.selectTBannerById(id);
        mmap.put("tBanner", tBanner);
        return prefix + "/edit";
    }

    /**
     * 修改保存banner配置
     */
    @RequiresPermissions("system:banner:edit")
    @Log(title = "banner配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TBanner tBanner)
    {
        return toAjax(tBannerService.updateTBanner(tBanner));
    }

    /**
     * 删除banner配置
     */
    @RequiresPermissions("system:banner:remove")
    @Log(title = "banner配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tBannerService.deleteTBannerByIds(ids));
    }
}
